<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <link href="./css/base.css" rel="stylesheet">
    <link href="./css/head.css" rel="stylesheet">
    <link href="./css/pets.css" rel="stylesheet">

<body>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/Utils.js"></script>

    <script src="js/mock.js"></script>
    <script src="mock/pet.js"></script>


    <div class="nav_head">
        <span>
            <a href="./index.html">首页</a>
        </span>
        <span>
            <a href="./pet_kinds.html">宠物</a>
        </span>

        <span>
            <a href="./pet_thing.html">宠物用品</a>
        </span>

        <span>
            <a href="./mine.html">个人中心</a>
        </span>
    </div>

    <div class="main">
        <div class="petBox">

        </div>
    </div>

    <script>
        init(Mock)
        let type = getSession('type')

        $.ajax({
            'url': baseUrl + 'type_pet_all.php?type=' + type,
            'type': 'GET',
            'success': function (res) {
                res = JSON.parse(res)

                let data = res.data

                if (res.code == 200) {
                    for (let i = 0; i < data.length; i++) {
                        $('.petBox').append(`
                        <div class="pet" onclick="toPet('${data[i].id}')">
                            <div class="image">
                                <img src="${baseUrl + data[i].image}" />    
                            </div>
                            <div class="petName"><b>${data[i].name}</b></div>
                            <div class="info">
                                <div class="petPrice">价格: ${data[i].price}</div>
                                <div class="stock">库存: ${data[i].stock}/只</div>

                            </div>
                        </div>
                        `)
                    }
                }else{
                    console.log(data.msg)
                }
            }
        })

        function toPet(id){
            location.href = "pet.html?id="+id
        }
    </script>

</body>

</html>